package com.ptone.messagecenter.modules.msg.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ptone.messagecenter.common.base.PageForm;
import com.ptone.messagecenter.modules.msg.dto.MsgRecordsDTO;
import com.ptone.messagecenter.modules.msg.entity.MsgRecords;
import com.ptone.messagecenter.modules.msg.mapper.MsgRecordsMapper;
import com.ptone.messagecenter.modules.msg.service.MsgRecordsService;
import com.ptone.messagecenter.modules.msg.util.MsgUtil;
import org.springframework.stereotype.Service;

/**
 * 消息记录：serviceImpl
 *
 * @author:Lance
 */
@Service
public class MsgRecordsServiceImpl extends ServiceImpl<MsgRecordsMapper, MsgRecords> implements MsgRecordsService {
    /**
     * 消息记录-insert
     *
     * @param msgRecordsDTO
     * @return
     */
    @Override
    public Boolean insert(MsgRecordsDTO msgRecordsDTO) {
        MsgRecords msgRecords = new MsgRecords(msgRecordsDTO);
        //获得消息体
        String message = MsgUtil.initMsg(msgRecordsDTO.getMsgTemplate(), msgRecordsDTO.getMsgTemplateValue());
        msgRecords.setMessage(message);
        return super.save(msgRecords);
    }

    /**
     * 消息记录-update
     *
     * @param entity
     * @return
     */
    @Override
    public Boolean update(MsgRecords entity) {
        return super.updateById(entity);
    }

    /**
     * 消息记录-delete
     *
     * @param info
     * @return
     */
    @Override
    public Boolean delete(MsgRecords info) {
        return info.deleteById();
    }

    /**
     * 消息记录-info
     *
     * @param info
     * @return
     */
    @Override
    public MsgRecords info(MsgRecords info) {
        return info.selectById();
    }

    /**
     * 消息记录-page
     *
     * @param form
     * @return
     */
    @Override
    public IPage<MsgRecords> page(PageForm<MsgRecords> form) {
        IPage<MsgRecords> page = form.newPage();
        return super.lambdaQuery().page(page);
    }
}
